<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.listid" placeholder="支付单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.username" placeholder="用户码" clearable></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-form-item label="订单时间:">
          <el-date-picker
            v-model="value2"
            :format="'yyyy-MM-dd HH:mm:ss'"
            :value-format="'yyyy-MM-dd HH:mm:ss'"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right">
          </el-date-picker>
        </el-form-item>
        <el-select v-model="dataForm.pay_status" placeholder="支付状态" clearable>
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-select v-model="dataForm.payment" placeholder="支付方式" clearable>
          <el-option
            v-for="item in options3"
            :key="item.value3"
            :label="item.label3"
            :value="item.value3">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="listid"
        header-align="center"
        align="center"
        min-width="220"
        label="外部交易单号">
      </el-table-column>
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        min-width="120"
        label="用户码">
      </el-table-column>
      <el-table-column
        prop="totalFee"
        header-align="center"
        align="center"
        min-width=""
        :formatter="formatMoney"
        label="总金额">
      </el-table-column>
      <el-table-column
        prop="memberFee"
        header-align="center"
        align="center"
        min-width=""
        :formatter="formatMoney1"
        label="会员价">
      </el-table-column>
      <el-table-column
        prop="payFee"
        header-align="center"
        align="center"
        min-width=""
        :formatter="formatMoney2"
        label="实际支付">
      </el-table-column>
      <el-table-column
        prop="balanceFee"
        header-align="center"
        align="center"
        min-width=""
        :formatter="formatMoney3"
        label="余额支付">
      </el-table-column>
      <el-table-column
        prop="activityFee"
        header-align="center"
        align="center"
        min-width=""
        label="优惠券抵扣">
      </el-table-column>
      <el-table-column
        prop="integralFee"
        header-align="center"
        align="center"
        min-width=""
        label="积分支付">
      </el-table-column>
      <el-table-column
        prop="integral"
        header-align="center"
        align="center"
        min-width=""
        label="积分">
      </el-table-column>
      <el-table-column
        prop="payment"
        header-align="center"
        align="center"
        min-width="100"
        label="支付方式">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.payment === 'alipay'" size="small" >支付宝</el-tag>
          <el-tag  v-if="scope.row.payment === 'weixin'" size="small" >微信</el-tag>
          <el-tag  v-if="scope.row.payment === 'paypal'" size="small" >paypal</el-tag>
          <el-tag  v-if="scope.row.payment === 'masapay'" size="small" >masapay</el-tag>
          <el-tag  v-if="scope.row.payment === 'offline'" size="small" >线下支付</el-tag>
          <el-tag  v-if="scope.row.payment === 'online'" size="small" >余额支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="addTimeStr"
        header-align="center"
        align="center"
        min-width="150"
        label="添加时间">
      </el-table-column>
      <el-table-column
        prop="payTimeStr"
        header-align="center"
        align="center"
        min-width="150"
        label="支付时间">
      </el-table-column>
      <el-table-column
        prop="payStatus"
        header-align="center"
        align="center"
        min-width=""
        label="支付状态">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.payStatus == 0" size="small" >已支付</el-tag>
          <el-tag v-if="scope.row.payStatus == 1" size="small" >未支付</el-tag>
        </template>
      </el-table-column>

      <!--<el-table-column
        prop="payId"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="spbillno"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态">
      </el-table-column>

      <el-table-column
        prop="operatorId"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="chargeFee"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="activityId"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="isNew"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="usd"
        header-align="center"
        align="center"
        label="">
      </el-table-column>-->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.payId)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './v9orderpay-add-or-update'
  export default {
    data () {
      return {
        value: '',
        visible: {},
        options: [{
          value: 0,
          label: '已支付'
        }, {
          value: 1,
          label: '未支付'
        }],
        value3: '',
        visible3: {},
        options3: [{
          value3: 'alipay',
          label3: '支付宝'
        }, {
          value3: 'weixin',
          label3: '微信'
        },{
          value3: 'paypal',
          label3: 'paypal'
        },{
          value3: 'masapay',
          label3: 'masapay'
        },{
          value3: 'offline',
          label3: '线下支付'
        },{
          value3: 'online',
          label3: '余额支付'
        }],
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
        value2: ''
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      formatMoney: function (row, column) {
        return row.totalFeeStr ='¥'+ parseFloat(row.totalFee).toFixed(2) ;
      },
      formatMoney1: function (row, column) {
        return row.memberFeeStr ='¥'+ parseFloat(row.memberFee).toFixed(2) ;
      },
      formatMoney2: function (row, column) {
        return row.payFeeStr ='¥'+ parseFloat(row.payFee).toFixed(2) ;
      },
      formatMoney3: function (row, column) {
        return row.balanceFeeStr ='¥'+ parseFloat(row.balanceFee).toFixed(2) ;
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let start,end;
        if(this.value2){
          start=this.value2[0];
          end=this.value2[1];
        }
        this.$http({
          url: this.$http.adornUrl('/order_pay/v9orderpay/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'listid': this.dataForm.listid,
            'user_id': this.dataForm.user_id,
            'pay_status': this.dataForm.pay_status,
            'username': this.dataForm.username,
            'start': start,
            'end': end,
            'payment': this.dataForm.payment
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.payId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/order_pay/v9orderpay/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
